package com.wntms.wy.service.impl;

import com.github.pagehelper.PageHelper;
import com.wntms.wy.dao.ErrorInformationDao;
import com.wntms.wy.pojo.ErrorInformation;
import com.wntms.wy.service.ErrorInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ErrorInformationServiceImpl implements ErrorInformationService {
    @Autowired
    private ErrorInformationDao errorInformationDao;

    @Override
    public Boolean panduanFCByFid(String fid) {
        int i = errorInformationDao.panduanFCByFid(fid);
        return i<1?false:true;
    }

    @Override
    public Boolean panduanEIByFid(String fid) {
        int ei = errorInformationDao.findEIByFid(fid);
        return ei<1?false:true;
    }

    @Override
    public Boolean puanduanIspass(String fid) {
        int ei1 = errorInformationDao.findSalesmanCountByFid(fid);
        Boolean b1 = errorInformationDao.findSalesmanIspassByFid(fid);
        int ei2 = errorInformationDao.findCustomerCountByFid(fid);
        Boolean b2 = errorInformationDao.findCustomerIspassByFid(fid);

        if (ei1 + ei2 >= 1){
            //说明至少存在业务员验收表
                if (!b1){
                    return true;
                }else if (!b2){
                    return true;
                }else {
                    return false;
                }
        }else {
            //说明还没有验收过
            return false;
        }

    }

    @Override
    public Boolean addErrorInformation(ErrorInformation errorInformation) {
        Boolean b1 = errorInformationDao.findSalesmanIspassByFid(errorInformation.getFid());
        Boolean b2 = errorInformationDao.findCustomerIspassByFid(errorInformation.getFid());
        //Boolean b3;
        if (!b1){
            Integer id = errorInformationDao.findIspassIdByfid1(errorInformation.getFid());
            errorInformation.setId(id);
            int i = errorInformationDao.addErrorInformation(errorInformation);
            return i<1?false:true;
        }else {
            Integer id2 = errorInformationDao.findIspassIdByfid2(errorInformation.getFid());
            errorInformation.setId(id2);
            int i = errorInformationDao.addErrorInformation(errorInformation);
            return i<1?false:true;
        }

    }

    @Override
    public Boolean deleteErrorInformation(Integer id) {
        int i = errorInformationDao.deleteErrorInformation(id);
        //System.out.println("我难道没进来？");
        return i<1?false:true;
    }

    @Override
    public Boolean updateErrorInformation(ErrorInformation errorInformation) {
        int i = errorInformationDao.updateErrorInformation(errorInformation);
        return i<1?false:true;
    }

    @Override
    public List<ErrorInformation> findAllErrorInformaton(Integer currentPage,Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<ErrorInformation> list = errorInformationDao.findAllErrorInformation();
        return list;
    }
}
